import weka.core.Instances;
import weka.filters.Filter;
import weka.filters.unsupervised.attribute.PrincipalComponents;

public class Part1Num1 {

	/**
	 * Does principal component analysis on instances input
	 * 
	 * @param instances
	 * @return pca instances if analysis successful, null otherwise
	 */
	public static Instances pca(final Instances instances) {

		final PrincipalComponents pca = new PrincipalComponents();
		Instances newInstances = null;

		try {

			pca.setInputFormat(instances);
			newInstances = Filter.useFilter(instances, pca);

		} catch (final Exception e) {
			System.out.println(e.toString());
			return null;
		}

		return newInstances;

	}

}
